package com.sgzn.sgpay.service.tcp.model.terminal.request;

import com.sgzn.sgpay.service.tcp.SgTcpProtocolHead;
import com.sgzn.sgpay.service.tcp.util.SgTcpUtil;
import lombok.Data;

/**
 * 后台账目清零 服务请求类
 * @author huangsenguang
 * @version Id: TcpBackBillSetZeroRequest.java, v 0.1 2018/7/23 9:19 huangsenguang Exp $$
 */
@Data
public class TcpBackBillSetZeroRequest extends TcpCommonRequest{
    /**
     * 长度
     */
    private String length="03";

    /**
     * 索引
     */
    private String index="01";

    /**
     * 命令
     */
    private String cmd="08";

    @Override
    public String toString(){
        //根据协议规范重载toString方法
        return beginCode + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                serialCode + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                deviceId + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                commandReq + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                head + length + index + cmd + getAllCheck(length + index + cmd ) + end + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                checkSumCode + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                endCode;
    }

    /**
     * 获取校验码
     * @param needToCheck
     * @return
     */
    private String getAllCheck(String needToCheck) {
        this.setCheck(SgTcpUtil.getToCheck(needToCheck));
        return this.check;
    }

    public static void main(String[] args){
        TcpBackBillSetZeroRequest tcpRequest = new TcpBackBillSetZeroRequest();
        tcpRequest.setDeviceId("10001");
        System.out.println(tcpRequest.toString());
    }
}

